// pages/check/map/map.js
var Charts = require('../../../module/utils/wxcharts-min.js');       //引入wxcharts.js  

// 为了使canvas在不同屏幕自适应进行以下换算
const W = wx.getSystemInfoSync().windowWidth;
const rate = 750.0 / W;
const code_w = 700 / rate;      
const code_h = 500 / rate;

Page({

  /**
   * 页面的初始数据
   */
  data: {
	  btn:1,
    code_w: code_w,      //柱状图的宽
    code_h: code_h,
	max:1000,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	wx.getStorage({
		key:'uid',
		success:(e)=>{
			console.log(e)
			wx.request({
				url:getApp().globalData.http1+'action=showZC&uid='+e.data.uid,
				success:(e)=>{
					console.log(e)
					this.setData({
						data:e.data.data,
						data1:e.data.data.days,
					})
					this.charts()
				}
			})
		}
	})
  },
  btn(e){
	  if(e.currentTarget.dataset.id==1){
		  this.setData({
		  		data1:this.data.data.days, 
				 btn:1
		  })
		  this.charts()
	  }else{
		  this.setData({
		  		data1:this.data.data.months,
				btn:2
		  })
		  this.charts()
	  }
  },
  charts:function(){
    let _this=this
    return new Promise(function () {
  
    new Charts({
      canvasId: 'columnCanvas',
      dataPointShape: false,
      type: 'column',
      legend: false,
      categories:_this.data.data1.week,
      xAxis: {
        disableGrid: true,
        type: 'calibration'
      },
      series: [{
        name: '营业额（元）',
        data:_this.data.data1.money,
        color: "rgba(255,90,87,1)"
        // color: "rgba(254,129,84,1)"
      }
      ],
      yAxis: {
        format: function (val) {
             return val ;
           },
        fontColor: "#ff6700"
      },
      dataItem: {
        color: "#ff6700"
      },
      width: code_w,
      height: code_h,
      extra: {
        column: {
          width: 15
        },
      }
    })
    })
  }
})
